<?php

namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Log;

class SUsers extends Model
{
    protected $hidden = [
        'is_robot',
    ];

    public function products(){
        return $this->belongsToMany('App\Models\Product','order_products','user_id','product_id')
            ->withPivot('product_name','image_id','current_price','activity_type','activity_id','quantity','total_price')
            ->orderBy('created_at','desc')
            ->withTimestamps();
    }

    public function getAvatarAttribute($value)
    {
        if ($this->is_robot == 0) {
            return $value;
        } else {
            return config('app.url') . $value;
        }
    }
}
